avahi: Be robust to missing refs in peer summaries
authorMatthew Leeds <matthew.leeds@endlessm.com>
Wed, 5 Sep 2018 04:49:23 +0000 (21:49 -0700)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 7 Sep 2018 10:19:24 +0000 (10:19 +0000)
commite4e6d85ea4e778c61b8f9a0301153dd0ee00b9b6
tree87addb8ed7f84f129f0c7a53ca6ab17e754c9edf
parenta70d2f67310bd869c6a40c4013dc51a3e2f2d2a8
avahi: Be robust to missing refs in peer summaries

In the OstreeRepoFinderAvahi implementation,
ostree_avahi_service_build_repo_finder_result() is where the DNS-SD
records are processed and turned into OstreeRepoFinderResult objects.
Each result object is supposed to have a hash table mapping refs to
checksums, so this is accomplished by first adding a placeholder (a ref
mapping to a NULL checksum) for each ref matched by the bloom filter,
and later filling in the checksums using the remote's summary file,
which happens in get_checksums(). The problem is that there's no
guarantee all the checksums will be resolved (non-NULL), so the
ostree_repo_finder_result_new() call then hits an assertion failure in
is_valid_collection_ref_map() leading to a crash (in the case that one
or more refs had NULL checksums).

There are at least two situations where the ref checksum might not be
found in the peer remote's summary file:
1) The bloom filter match was a false positive. This is going to happen
sometimes by design.
2) The peer remote's summary is out of sync with its DNS-SD records.
This shouldn't normally happen but it's still good to be robust to the
possibility; in Endless OS nothing guarantees the atomicity of updating
the summary and DNS-SD records.

This commit changes libostree to be robust to the possibility of refs
missing from the peer remote's summary, by removing any that still have
a NULL checksum associated with them after the summary has been fetched
and processed.

The other OstreeRepoFinder implementations don't have this issue because
they use summary files directly and therefore always have access to the
checksum.

Closes: #1717
Approved by: pwithnall
src/libostree/ostree-repo-finder-avahi.c